package com.suge.message.dao.impl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.suge.common.result.message.MessageResult;
import com.suge.message.dao.SmsMessageDAO;
import com.suge.message.dao.dataobject.SmsMessageDO;

public class SmsMessageDAOImpl  extends SqlMapClientDaoSupport implements SmsMessageDAO {

	public MessageResult getSmsMessageTempleteById(long messageId) {
		SmsMessageDO smsMessageDO = (SmsMessageDO) this.getSqlMapClientTemplate().queryForObject("SmsMessage.querySmsMessageByTempleteId",messageId);
		MessageResult messageRes = new MessageResult();
		messageRes.setSuccess(false);
		if(smsMessageDO!=null && smsMessageDO.getStatus()==0){
			messageRes.getSuccessList().add(smsMessageDO);
			messageRes.getSuccessIdList().add(smsMessageDO.getMessageId());
			messageRes.setSuccess(true);
		}
		return messageRes;
	}

	public MessageResult getSmsMessageTempletesByTypeId(int typeId) {
		@SuppressWarnings("unchecked")
		List<SmsMessageDO> messageList = this.getSqlMapClientTemplate().queryForList("SmsMessage.querySmsMessageTempletesByTypeId", (long)(typeId));
		MessageResult messageRes = new MessageResult();
		messageRes.setSuccess(false);
		if(messageList!=null && messageList.size()>0){
			messageRes.setSuccessList(messageList);
			messageRes.setSuccess(true);
		}
		return messageRes;
	}

	public MessageResult updateSmsTemplete(SmsMessageDO smsMessageDO) {
		boolean res = this.getSqlMapClientTemplate().update("SmsMessage.updateSmsMessageTempleteInfo", smsMessageDO)>0;
		MessageResult messageRes = new MessageResult();
		messageRes.setSuccess(res);

		return messageRes;
	}

	public MessageResult insertSmsTemplete(SmsMessageDO smsMessageDO) {
		boolean res = this.getSqlMapClientTemplate().insert("SmsMessage.insertSmsMessageTemplete", smsMessageDO)!=null;
		MessageResult messageRes = new MessageResult();
		messageRes.setSuccess(res);

		return messageRes;
	}

	public MessageResult getSmsMessageTempletesByUserNick(String userNick) {
		@SuppressWarnings("unchecked")
		List<SmsMessageDO> messageList = this.getSqlMapClientTemplate().queryForList("SmsMessage.querySmsMessageTempletesByUserNick", userNick);
		MessageResult messageRes = new MessageResult();
		messageRes.setSuccess(false);
		if(messageList!=null && messageList.size()>0){
			messageRes.setSuccessList(messageList);
			messageRes.setSuccess(true);
		}
		return messageRes;
	}

	public MessageResult getSmsMessageTempletesByUserId(long userId) {
		@SuppressWarnings("unchecked")
		List<SmsMessageDO> messageList = this.getSqlMapClientTemplate().queryForList("SmsMessage.querySmsMessageTempletesByUserId", userId);
		MessageResult messageRes = new MessageResult();
		messageRes.setSuccess(false);
		if(messageList!=null && messageList.size()>0){
			messageRes.setSuccessList(messageList);
			messageRes.setSuccess(true);
		}
		return messageRes;
	}

}
